﻿using System.IO;
using System.Text;

namespace Z.GenerateIconProject.WinForm
{
    public partial class IconLibraryHelper
    {
        public static string GetCssText(ProjectConfig project)
        {
            var sb = new StringBuilder();

            foreach (IconConfig item in project.IconConfigs)
            {
                sb.Append(GetCssText(project, item));
            }

            return sb.ToString();
        }

        public static string GetCssText(ProjectConfig project, IconConfig config)
        {
            const string template = ".@(Model.DestinationName)_@(Model.IconName){background-image:url('@(Model.HandlerPath)?f=@(Model.DestinationName).@(Model.FileName)')}";
            var sb = new StringBuilder();

            foreach (FileInfo file in config.SourcePath.ToDirectoryInfo().GetFiles())
            {
                string s = template;
                s = s.Replace("@(Model.DestinationName)", config.DestinationName);
                s = s.Replace("@(Model.IconName)", GetIconName(file));
                s = s.Replace("@(Model.HandlerPath)", project.Namespace + ".axd");
                s = s.Replace("@(Model.FileName)", file.Name);

                sb.AppendLine(s);
            }
            return sb.ToString();
        }
    }
}